package tree;

/**
 * @author： pang-yun
 * @date： 2021-12-07 15:40
 * 功能目的 ：用于
 */

public class Tree {
    private Node pre = null;


    public void threaded(Node node) {
        if (node == null) return;
        threaded(node.getLeftNode());

        if (node.getLeftNode() == null) {
            node.setLeftNode(pre);
            node.setLeftType(1);
        }

        if (pre != null && pre.getRightNode() == null) {
            pre.setRightNode(node);
            pre.setRightType(1);
        }

        pre = node;

        threaded(node.getRightNode());

    }

    //遍历
    public void treeList(Node node) {
        if (node == null) return;
        while (node != null) {
            while (node.getLeftType() == 0) {
                node = node.getLeftNode();
            }
            System.out.println(node);

            while (node.getRightType()==1){
                node = node.getRightNode();
                System.out.println(node);
            }
            node= node.getRightNode();
        }
    }
}
